#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


class Main(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)
        self.setWindowTitle('Radio Button')
        self.setGeometry(300, 300, 300, 300)
        grid = QtGui.QGridLayout()
        self.setLayout(grid)

        self.rblist = {'rb1':'a', 'rb2':'b'}
        # for rb in [(k, self.rblist[k]) for k in sorted(self.rblist.keys())]:
        #     rbname = rb[0]
        #     rbtext = rb[1]
        #     print rbname, rbtext
        #     self.rbname = QtGui.QRadioButton(rbtext)
        #     grid.addWidget(self.rbname)
        #     # self.connect(self.rbname, QtCore.SIGNAL('clicked()'), self.showrbcheckstatus)
        self.rb1 = QtGui.QRadioButton('a')
        self.rb1.setChecked(True)
        grid.addWidget(self.rb1)
        self.rb2 = QtGui.QRadioButton('b')
        grid.addWidget(self.rb2)

        self.le1 = QtGui.QLineEdit('which RadioButton is checked?')
        grid.addWidget(self.le1)

        self.connect(self.rb1, QtCore.SIGNAL('clicked()'), self.showrbcheckstatus)
        self.connect(self.rb2, QtCore.SIGNAL('clicked()'), self.showrbcheckstatus)

    def showrbcheckstatus(self):
        # for rb in [(k, self.rblist[k]) for k in sorted(self.rblist.keys())]:
        #     rbname = rb[0]
        #     if self.rbname.isChecked():
        #         print rbname + ' is checked!'
        if self.rb1.isChecked():
            print 'rb1 is checked!'
            self.le1.setText('rb1 is checked!')
        if self.rb2.isChecked():
            print 'rb2 is checked!'
            self.le1.setText('rb2 is checked!')


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())